#ifndef JGLOBALS_H
#define JGLOBALS_H
#include <string>
#include <unordered_map>
#include <boost/any.hpp>
#include <memory>

struct LoginInfo{
    std::wstring RYXM;
    std::wstring RYBH;
    std::wstring RYXB;
    std::wstring RYLX;
    std::wstring KSMC;
    std::wstring KSDM;
};
typedef std::shared_ptr<LoginInfo> LoginInfoPtr;
#define GV_LOGIN_INFO  L"登录信息"

class JGlobals
{
private:
    inline JGlobals(){}
protected:
    static std::unordered_map<std::wstring,boost::any> s_global;
public:
    static void SetAny(const std::wstring & key,boost::any & value);
    static bool GetAny(const std::wstring & key,boost::any & value);
    static bool HasKey(const std::wstring & key);
    static bool Erase(const std::wstring & key);
    template<typename T>
    static T GetValue(const std::wstring & key)
    {
        boost::any value;
        if(JGlobals::GetAny(key,value))
        {
            return boost::any_cast<T>(value);
        }else{
            return T();
        }
    }
    template<typename T>
    static void SetValue(const std::wstring & key,const T & t)
    {
        boost::any value=t;
        JGlobals::SetAny(key,value);
    }
    template<typename T>
    static T GetValue(const wchar_t* key)
    {
        return GetValue<T>(std::wstring(key));
    }
    template<typename T>
    static void SetValue(const wchar_t* key,const T & t)
    {
       SetValue<T>(std::wstring(key),t);
    }

};

#endif // JGLOBALS_H
